home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 21
/
Aminet 21 (1997)(GTI - Schatztruhe)[!][Oct 1997].iso
/
Aminet
/
util
/
sys
/
AllocP.lha
/
AllocP
/
AllocP.c
< prev
next >
Wrap
C/C++ Source or Header
|
1997-08-24
|
7KB
|
209 lines
/************************************************************************
* *
* AllocP - supply a better AllocMem/AllocVec *
* *
* written by Andreas R. Kleinert *
* Andreas_Kleinert@t-online.de *
* *
* No Assembler - 100 percent C *
* *
* V1.3 : *
* - when the real "avail flush" process took place, *
* a memory loss could have occured *
* - added Forbid/Permit *
* - fixed/changed some other stuff *
* *
* V1.2 : *
* - redone with SAS/C 6.58 *
* - now checks for MEMF_NO_EXPUNGE *
* - utility.library was not needed *
* - fixed requester layout *
* - fixed #include list *
* - now 68020 compiled (040 before, thus 020 ;-) *
* - fixed $VERsion string *
* - etc. *
* - saved > 400 Bytes *
* *
* V1.1 : *
* - V37 works, too *
* - alignment feature was broken *
* - reduced stack size *
* *
* V1.0 : *
* - first release *
* *
************************************************************************/
#define __USE_SYSBASE
#include <exec/execbase.h>
#include <exec/memory.h>
#include <intuition/intuition.h>
#include <string.h>
#include <stdio.h>
#include <proto/exec.h>
#include <proto/dos.h>
#include <proto/intuition.h>
#define N (NULL)
extern struct ExecBase *SysBase;
struct IntuitionBase *IntuitionBase = N;
APTR __far NewAllocMemVec;
ULONG __far __asm (*OrigAllocMemVec)(register __d0 ULONG size,
register __d1 ULONG memf,
register __a6 struct ExecBase *ExecBase_a6);
APTR __far NewAllocVecVec;
ULONG __far __asm (*OrigAllocVecVec)(register __d0 ULONG size,
register __d1 ULONG memf,
register __a6 struct ExecBase *ExecBase_a6);
ULONG __asm NewAllocMem(register __d0 ULONG size,
register __d1 ULONG memf,
register __a6 struct ExecBase *ExecBase_a6)
{
ULONG ptr;
ptr = OrigAllocMemVec(size, memf, ExecBase_a6);
if(!ptr)
{
if(size <= 0xFFFFFF00) /* otherwise this was a "flush" call, only */
{
if(!(memf & MEMF_NO_EXPUNGE)) OrigAllocMemVec((ULONG) 0xFFFFFFFF, MEMF_ANY, ExecBase_a6);
ptr = OrigAllocMemVec(size, memf, ExecBase_a6);
}
}
return((ULONG) ptr);
}
ULONG __asm NewAllocVec(register __d0 ULONG size,
register __d1 ULONG memf,
register __a6 struct ExecBase *ExecBase_a6)
{
ULONG ptr, nsize, gap;
if(gap = ((nsize=size) & 3))
{
nsize = size + (4 - gap); /* avoid alignment gaps */
if(size > nsize) nsize = size; /* we produced an overflow */
}
ptr = OrigAllocVecVec(nsize, memf, ExecBase_a6);
if(!ptr)
{
if(size <= 0xFFFFFF00) /* otherwise this was a "flush" call, only */
{
if(!(memf & MEMF_NO_EXPUNGE)) OrigAllocMemVec((ULONG) 0xFFFFFFFF, MEMF_ANY, ExecBase_a6);
ptr = OrigAllocVecVec(nsize, memf, ExecBase_a6);
}
}
return((ULONG) ptr);
}
/* *************************************************** */
/* * * */
/* * Compiler Stuff for BackgroundIO * */
/* * * */
/* *************************************************** */
long __stack = 1024;
char *__procname = "AllocP";
long __priority = 1;
long __BackGroundIO = 1;
void __regargs __chkabort(void) { }
void __regargs _CXBRK(void) { }
char vertext [] = "\0$VER: AllocP 1.1 (16.8.97)";
long main(long argc, char **argv)
{
long retval = 0;
APTR task;
Forbid();
task = FindTask(N);
Permit();
if(task) SetTaskPri(task, __priority);
IntuitionBase = (APTR) OpenLibrary("intuition.library", 37);
if(IntuitionBase)
{
Forbid();
OrigAllocMemVec = (long (* __asm )(register __d0 ULONG size,
register __d1 ULONG memf,
register __a6 struct ExecBase *ExecBase_a6)) SetFunction((APTR)SysBase, -0xc6, (APTR)NewAllocMem);
OrigAllocVecVec = (long (* __asm )(register __d0 ULONG size,
register __d1 ULONG memf,
register __a6 struct ExecBase *ExecBase_a6)) SetFunction((APTR)SysBase, -0x2ac, (APTR)NewAllocVec);
Permit();
if(OrigAllocMemVec || OrigAllocVecVec)
{
if(task) SetTaskPri(task, -10);
Wait(SIGBREAKF_CTRL_C);
if(task) SetTaskPri(task, 1);
Forbid();
NewAllocMemVec= (APTR) SetFunction((APTR)SysBase, -0xc6, (APTR)OrigAllocMemVec);
NewAllocVecVec= (APTR) SetFunction((APTR)SysBase, -0x2ac, (APTR)OrigAllocVecVec);
Permit();
if(NewAllocMemVec!=NewAllocMem)
{
ULONG idcmp = N;
struct EasyStruct estr;
estr.es_StructSize = sizeof(struct EasyStruct);
estr.es_Flags = N;
estr.es_Title = "AllocP Request";
estr.es_TextFormat = "Error while removing from system !\n"
"There were more patches !\n"
"Do a reset soon !";
estr.es_GadgetFormat = "Ok";
EasyRequestArgs(N, &estr, (ULONG *) &idcmp, N);
}
if(NewAllocVecVec!=NewAllocVec)
{
ULONG idcmp = N;
struct EasyStruct estr;
estr.es_StructSize = sizeof(struct EasyStruct);
estr.es_Flags = N;
estr.es_Title = "AllocP Request";
estr.es_TextFormat = "Error while removing from system !\n"
"There were more patches !\n"
"Do a reset soon !";
estr.es_GadgetFormat = "Ok";
EasyRequestArgs(N, &estr, (ULONG *) &idcmp, N);
}
}else retval = 20;
CloseLibrary((struct Library *) IntuitionBase);
}else retval = 20;
return(retval);
}